package com.itheima01;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;


public class JDBCDemo {
    public static void main(String[] args) throws Exception {
        //1导包
        //2注册驱动
        Class.forName("com.mysql.jdbc.Driver");

        Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/db7", "root", "root");

        Statement stat = con.createStatement();

        String sql = "select * from city";

        ResultSet rs = stat.executeQuery(sql);

        while (rs.next()) {
            System.out.println(rs.getInt("id")+"\t"+rs.getString("city_name")+"\t"+rs.getInt("cid"));
        }

        rs.close();
        stat.close();
        con.close();

    }
}
